package org.ne.banksys.service.serviceImpl;

import com.github.pagehelper.Page;
import org.ne.banksys.entity.Trade;
import org.ne.banksys.mapper.TradeMapper;
import org.ne.banksys.service.TradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wey
 * @date 2025/6/13 下午10:43 06
 **/

@Service
public class TradeServiceImpl implements TradeService {

    @Autowired
    private TradeMapper tradeMapper;


    @Override
    public List<Trade> getAll() {
        return tradeMapper.getAll();
    }

    @Override
    public void add(Trade trade) {
        tradeMapper.insert(trade);
    }

    @Override
    public void delete(Long tradeId) {
        tradeMapper.delete(tradeId);
    }

    @Override
    public void update(Trade trade) {
        tradeMapper.update(trade);
    }

    @Override
    public Trade getById(Long id){
        return tradeMapper.get(id);
    }

    @Override
    public Page<Trade> getAllTrades(Integer page, Integer size) {
        if (page == 1) {
            page = 0;
        }
        return tradeMapper.getPage(page, size);
    }




    /**
     * 根据交易金额范围筛选记录

     * @param minMoney  最小金额（可空）
     * @param maxMoney  最大金额（可空）
     * @return 符合条件的交易列表
     */

    @Override
    public List<Trade> filterByTradeMoney(
            BigDecimal minMoney,
            BigDecimal maxMoney
    ) {
        return tradeMapper.findByTradeMoneyRange(minMoney, maxMoney);
    }



    /**
     * 根据交易日期范围筛选记录

     * @param startDate  起始日期（可空）
     * @param endDate    结束日期（可空）
     * @return 符合条件的交易列表
     */
    @Override
    public List<Trade> filterByTradeDate(
            Timestamp startDate,
            Timestamp endDate
    ) {
        return tradeMapper.findByTradeDateRange(startDate, endDate);
    }

    @Override
    public List<Trade> filterByDateAndMoney(BigDecimal minMoney, BigDecimal maxMoney, Timestamp startDate, Timestamp endDate) {
        return tradeMapper.findByMoneyAndDate(minMoney, maxMoney, startDate, endDate);
    }

}